package com.zbkj.front.controller;

import com.zbkj.dal.pojo.response.ProductBrandResponse;
import com.zbkj.dal.base.result.CommonResult;
import com.zbkj.service.service.ProductBrandService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.stream.Collectors;

/**
 * @author tianzhonghai
 * 2023/10/22 14:27
 */
@Slf4j
@RestController
@RequestMapping("api/front/product/brand")
@Api(tags = "商品品牌控制器")
public class ProductBrandController {

    @Autowired
    private ProductBrandService productBrandService;

    /**
     * 输入建议
     *
     * @param keyword
     * @return
     */
    @ApiOperation(value = "按关键字获取品牌")
    @RequestMapping(value = "/suggestions", method = RequestMethod.GET)
    public CommonResult<List<ProductBrandResponse>> suggestions(String keyword, Integer limit) {
        return CommonResult.success(productBrandService.suggestions(keyword, limit));
    }

    @ApiOperation(value = "所有品牌", tags = "商品列表")
    @RequestMapping(value = "/listAll", method = RequestMethod.GET)
    public CommonResult<List<ProductBrandResponse>> listAll() {
        List<ProductBrandResponse> cacheAllList = productBrandService.getCacheAllList();
        cacheAllList = cacheAllList.stream().filter(p -> p.getIsShow() != null && p.getIsShow()).collect(Collectors.toList());
        return CommonResult.success(cacheAllList);
    }
}
